package com.example.pilipili.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class R<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    private int code;
    private String msg;
    private T data;

    public static <T> R<T> ok() {
        return (R<T>) restResult((Object)null, CommonConstants.SUCCESS, (String)null);
    }

    public static <T> R<T> ok(T data) {
        return restResult(data, CommonConstants.SUCCESS, (String)null);
    }

    public static <T> R<T> ok(T data, String msg) {
        return restResult(data, CommonConstants.SUCCESS, msg);
    }

    public static <T> R<T> failed() {
        return (R<T>) restResult((Object)null, CommonConstants.FAIL, (String)null);
    }

    public static <T> R<T> failed(String msg) {
        return (R<T>) restResult((Object)null, CommonConstants.FAIL, msg);
    }

    public static <T> R<T> failed(T data) {
        return restResult(data, CommonConstants.FAIL, (String)null);
    }

    public static <T> R<T> failed(T data, String msg) {
        return restResult(data, CommonConstants.FAIL, msg);
    }

    public static <T> R<T> error(String msg) {
        return (R<T>) restResult((Object)null, CommonConstants.ERROR, msg);
    }

    public static <T> R<T> error(T data) {
        return restResult(data, CommonConstants.ERROR, (String)null);
    }

    public static <T> R<T> error(T data, String msg) {
        return restResult(data, CommonConstants.ERROR, msg);
    }


    public static <T> R<T> restResult(T data, int code, String msg) {
        R<T> apiResult = new R();
        apiResult.setCode(code);
        apiResult.setData(data);
        apiResult.setMsg(msg);
        return apiResult;
    }

    public String toString() {
        return "R(code=" + this.getCode() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")";
    }

    public R() {
    }

    public R(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


}
